package com.qd.common.flow.domain.bill;

import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * 审批业务
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class FlowBillDTO extends BaseQuery {

    /**
     * 主键
     */
    @NotBlank(message = "审批业务ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "审批业务ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String billId;
    /**
     * 流程编码
     */
    @NotBlank(message = "流程编码不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "流程编码长度不能超过{max}位", groups = DefaultGroup.class)
    private String processCode;
    /**
     * 流程名称
     */
    @NotBlank(message = "流程名称不能为空", groups = DefaultGroup.class)
    @Size(max = 200, message = "流程名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String processName;
    /**
     * 业务关联ID
     */
    @NotBlank(message = "业务关联ID不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "业务关联ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String bid;
    /**
     * 创建时间
     */
    private LocalDateTime createTime;
    /**
     * 完成时间
     */
    private LocalDateTime finishTime;
    /**
     * 任务名称
     */
    @NotBlank(message = "任务名称不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "任务名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String taskName;
    /**
     * 业务状态:0进行中1已结束
     */
    private Integer billState;
    /**
     * 流程发起人
     */
    @Size(max = 100, message = "流程发起人长度不能超过{max}位", groups = DefaultGroup.class)
    private String processUserName;
    /**
     * 流程发起组织
     */
    @Size(max = 100, message = "流程发起组织长度不能超过{max}位", groups = DefaultGroup.class)
    private String processOrgName;
    /**
     * 流程ID
     */
    @NotBlank(message = "流程ID不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "流程ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String processId;
    /**
     * 操作类型
     */
    @NotBlank(message = "操作类型不能为空", groups = DefaultGroup.class)
    @Size(max = 64, message = "操作类型长度不能超过{max}位", groups = DefaultGroup.class)
    private String operatorType;
    /**
     * 流程发起人ID
     */
    @Size(max = 50, message = "流程发起人ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String processUserId;
    /**
     * 流程发起组织ID
     */
    @Size(max = 50, message = "流程发起组织ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String processOrg;
    /**
     * 审批任务
     */
    private FlowTaskDTO task;
    /**
     * 历史任务
     */
    private FlowHisTaskDTO hisTask;

    @Override
    public void freeData() {
        this.billId = null;
        this.processCode = null;
        this.processName = null;
        this.bid = null;
        this.createTime = null;
        this.finishTime = null;
        this.taskName = null;
        this.billState = null;
        this.processUserName = null;
        this.processOrgName = null;
        this.processId = null;
        this.operatorType = null;
        this.processUserId = null;
        this.processOrg = null;
        Optional.ofNullable(task).ifPresent(FlowTaskDTO::freeData);
        Optional.ofNullable(hisTask).ifPresent(FlowHisTaskDTO::freeData);
        super.freeData();
    }
}
